package com.qf.dao;

import com.qf.pojo.User;
import com.qf.utils.DBUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author mkr
 * @version V1.0
 * @Project java2203-mkr
 * @Package com.qf.dao
 * @Description:
 * @Date 2022/5/27 19:23
 */
public class AdminDaoImpl implements AdminDao {

    //创建dbUtils工具
    private QueryRunner queryRunner = new QueryRunner(DBUtil.getDateSource());
    /**
     * 通过用户名查找用户
     * @param username
     * @return
     */
    @Override
    public User findName(String username) {
        String sql = "select * from user where username=?";
        try {
            User user = queryRunner.query(sql, new BeanHandler<User>(User.class),username);
            return user;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
